package com.atguigu.gmall.product.contioller;

import com.atguigu.gmall.common.cache.GmallCache;
import com.atguigu.gmall.model.product.BaseCategoryView;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.model.product.SpuSaleAttr;
import com.atguigu.gmall.product.mapper.SkuInfoMapper;
import com.atguigu.gmall.product.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * description:
 * create by sxy 2021/5/12
 * 此类是为了其他微服务远程调用所使用的
 */
@RestController
@RequestMapping("/api/product")
public class ProductApiController {
    @Autowired
    private ManagerService managerService;

    //  1. Skuinfo 商品库存详情
//	. Skuinfo 商品库存图片
    //加上inner字样表示是内部资源，不允许外部访问，也就是不接受从网关过来,写了网关全局过滤器之后inner才会起作用
    @GetMapping("/inner/getSkuInfo/{skuId}")
    public SkuInfo getSkuInfo(@PathVariable Long skuId) {

        return managerService.getSkuInfo(skuId);
    }

    //	2. 1、2、3、级分类名称
    @GetMapping("/inner/getBaseCategoryView/{category3Id}")
    public BaseCategoryView getBaseCategoryView(@PathVariable Long category3Id) {
        return managerService.getBaseCategoryView(category3Id);
    }

    //	3. 销售属性及值
    @GetMapping("/inner/getSpuSaleAttrValueChecked/{skuId}/{spuId}")
    public List<SpuSaleAttr> getSpuSaleAttrValueChecked(@PathVariable Long skuId,
                                                        @PathVariable Long spuId) {
        return managerService.getSpuSaleAttrValueChecked(skuId, spuId);

    }

    //  4.销售属性组合获取对应的skuid
    @GetMapping("/inner/getValuesSkuJson/{spuId}")
    public Map getValuesSkuJson(@PathVariable Long spuId) {
        return managerService.getValuesSkuJson(spuId);

    }

    //5 单独查询价格，目的是不放在缓存中
    @GetMapping("/inner/getPrice/{skuId}")
    public BigDecimal getPrice(@PathVariable Long skuId) {
        return managerService.getPrice(skuId);
    }

}


